package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.server.service.CommentsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
@Slf4j
@RestController
@RequestMapping("/comments")
public class CommentsController {

    @Autowired
    private CommentsService commentsService;

    /**
     * 保存评论
     *
     * @param map
     * @return
     */
    @PostMapping
    private ResponseEntity saveComments(@RequestBody Map map) {
        String movementId = (String) map.get("movementId");
        String comment = (String) map.get("comment");
        commentsService.saveComments(movementId, comment);
        return ResponseEntity.ok(null);
    }

    /**
     * 分页查询评论列表
     */
    @GetMapping
    public ResponseEntity findComments(@RequestParam(defaultValue = "1") Integer page,
                                       @RequestParam(defaultValue = "10") Integer pagesize,
                                       String movementId) {
      PageResult pr =  commentsService.findComments(page,pagesize,movementId);
      return ResponseEntity.ok(pr);
    }

    /**
     * 查询评论点赞
     * @param id
     * @return
     */
    @GetMapping("/{id}/like")
    public ResponseEntity likeComment(@PathVariable String id){
       Integer count = commentsService.Commentlike(id);
       return ResponseEntity.ok(count);
    }
}
